<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"  xmlns:sec="http://www.thymeleaf.org/extras/spring-security">

<div id="page-content">
    <div class="row" id="targetDesc-btn-row">
        <div class="col-sm-6 table-toolbar-left">
            <button type="button" class="btn btn-primary btn-sm" id="btn-targetDesc-add" th:disabled="${!isCreator}">新建指标描述</button>
        </div>
    </div>

    <div class="jqGrid_wrapper">
        <table id="targetDesc_table"></table>
        <div id="targetDesc_page"></div>
    </div>
</div>

<script th:inline="javascript">

    $(function(){
        init_grid_targetDescDict();
        setTimeout(function(){
            __jqGrid_width("targetDesc_table", $("#targetDesc-btn-row").width())
        }, 300);
    });

    function init_grid_targetDescDict(){
        __init_jqgrid('targetDesc_table', 'targetDesc_page', ctx + 'targetDesc/list_targetDescDict?targetId='+[[${parentId}]],
            ["指标定义","id"],
            [
                {name: 'name', index: 'name', width: 100, sortable: false, searchoptions: {sopt: ['cn']}},

                {name: 'id', index: 'id', width: 100, key: true, hidden: true}
            ],false,{
                subGrid : true,
                subGridRowExpanded : init_grid_targetDesc
            }
        );
    }

    function init_grid_targetDesc(subgrid_id, row_id){
        var subgrid_table_id = subgrid_id + "_t";
        var subgrid_page_id = subgrid_id + "_p";
        $("#" + subgrid_id).html("<table id='" + subgrid_table_id + "' class='scroll'></table><div id='"+subgrid_page_id+"'></div></div>");
        __init_jqgrid(subgrid_table_id, subgrid_page_id,ctx + 'targetDesc/list?targetId='+[[${parentId}]]+'&targetDescDictId='+row_id,
            ["定义描述","点赞数","最后更新时间","当前版本","操作","id"],
            [
                {name:'content', index:'content', width:100, search:true, sortable:false, searchoptions: {sopt: ['cn']}},
                {name:'zanCount', index:'zanCount', width:20, search:true, sortable:false, searchoptions: {sopt: ['eq']}},
                {name:'lastUpdateTime', index:'lastUpdateTime', width:20, search:true, sortable:false, searchoptions: {sopt: ['cn']}},
                {name:'version', index:'version', width:20, search:true, sortable:false, searchoptions: {sopt: ['cn']}},
                {name: 'act', index: 'act', width: 20, sortable: false, search: false, formatter: actFormat_targetDesc},
                {name:'id',index:'id',search:false,hidden:true}
            ]
        );
    }

    function actFormat_targetDesc(cellvalue, options, rowObject){
        var id = rowObject.id;
        cellvalue = '<button class="btn btn-default btn-xs" onclick="fn_targetDesc_read(\'' + id + '\');">查看</button> ';
        cellvalue += '<button class="btn btn-primary btn-xs" onclick="fn_targetDesc_update(\'' + id + '\');">更新</button> ';
        return cellvalue;
    }

    //input
    $("#btn-targetDesc-add").on("click", function(){
        __layX_html_read("create", "指标描述", "/targetDesc/input?parentId="+[[${parentId}]], {width : "75%", height : "75%"});
    });

    //read
    function fn_targetDesc_read(id){
        __layX_html_read(id, "指标描述", "/targetDesc/read?keyId="+id, {width : "75%", height : "75%"});
    }

    //更新
    function fn_targetDesc_update(id){
        __layX_html_read(id, "指标描述", "/targetDesc/input?editType=update&keyId="+id);
    }

</script>

</html>